﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;
using System.Data;

namespace HZ.Supervise.Web.Hospital
{
    public partial class HospitalPurchasePlanByNormalDetail :BasePage
    {
        
        IExecuteContext iec = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_Sort isort = HZ.Supervise.BLLFactory.IBLL_Sort();
        public HospitalPurchasePlanByNormalDetail()
        {
            this.ModuleNo = Module.医院统计分析.ToString();
            this.PageOperateType = OperateType.医院预采购计划填报情况.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                rblSortBind();
            }
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        { 
            BindData();

        }
        /// <summary>
        /// 绑定药品类别
        /// </summary>
        private void rblSortBind()
        {
            //绑定中标目录类型
            DataTable dt = isort.GetSort();
            dlpsort.DataSource = dt;
            dlpsort.DataValueField = "SortID";
            dlpsort.DataTextField = "SortName";
            dlpsort.DataBind();

            this.dlpsort.Items.Insert(0, new ListItem("全部", ""));
        }
        /// <summary>
        /// 绑定数据
        /// modify  by张雄  2011.5.4
        /// </summary>
        public void BindData()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.GetHospitalPurchasePlanListByNormalDetail(vs, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            AspNetPager1.RecordCount = t;

            this.gvwInfo.PageSize = AspNetPager1.PageSize;
            this.gvwInfo.DataSource = dt;
            this.gvwInfo.DataBind();



        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }
         

        /// <summary>
        /// 导出 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.GetHospitalPurchasePlanListByNormalDetail(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);
        }



        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery(); 
            vs = (SuperviseQuery)Session[Request.QueryString["sesid"]];
            vs.ProcureCatalogID = txtProcureCatalogID.Text.Trim();
            vs.ProductName = null;
            vs.PinyinCode = null;
            vs.SortID = dlpsort.SelectedValue;
            if (HZ.Common.zhHansUtil.HaveChineseCode(txtProductName.Text.Trim()))
            {
                vs.ProductName = txtProductName.Text.Trim();
            }
            else
            {
                vs.PinyinCode = txtProductName.Text.Trim();
            }
            vs.MedicineModelName = txtMedicineModel.Text.Trim();
            vs.Pack = txtPack.Text.Trim();
            if (!string.IsNullOrEmpty(Convert.ToString(vs.PurChaseTime)))
            {
                txtPurchaseTime.Text = Convert.ToString(vs.PurChaseTime);
            }
            if (!string.IsNullOrEmpty(txtPurchaseTime.Text.Trim()))
            {
                vs.PurChaseTime = Convert.ToDateTime(txtPurchaseTime.Text.Trim());
            }
            else
            { vs.PurChaseTime = null; }
            vs.SortFields = ddlSortFields.SelectedValue +" "+ ddlSort.SelectedValue;
            return vs;
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            string url = "HospitalPurchasePlanByNormal.aspx?sesid=" + Request.QueryString["sesid"];
                 
            Response.Redirect(url);
        }
    }
}
